﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using StockFinder.Model;

namespace StockFinder.DataAccess
{
    public class IndicatorDataAccess : DataAccessBase
    {
        private const string INSERT_SYMBOL_RELATIVE_STRENGTH_COMMAND = "dbo.InsertSymbolRelativeStrength";
        private const string TRUNCATE_TABLE_SYMBOL_PERFORMANCE = "[dbo].[TruncateTableSymbolPerformance]";

        public static void InsertSymbolRelativeStrength(int symbolId, DateTime pricedate, decimal performance)
        {            
            using (SqlConnection connection = new SqlConnection(ApplicationConfiguation.DatabaseConnectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand(INSERT_SYMBOL_RELATIVE_STRENGTH_COMMAND, connection) { CommandType = System.Data.CommandType.StoredProcedure })
                {
                    command.Parameters.AddWithValue("@SymbolId", symbolId);
                    command.Parameters.AddWithValue("@Date", pricedate);
                    command.Parameters.AddWithValue("@Performance", performance);                    

                    command.ExecuteNonQuery();

                    //symbol.SymbolId = result;
                }
            }
        }

        public static void TruncateTableSymbolPerformance()
        {
            using (SqlConnection connection = new SqlConnection(ApplicationConfiguation.DatabaseConnectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("truncate table symbolperformance", connection) { CommandType = System.Data.CommandType.Text })
                {
                    command.ExecuteNonQuery();
                }
            }
        }

        public static void TruncateTableSymbolRelativeStrength()
        {
            using (SqlConnection connection = new SqlConnection(ApplicationConfiguation.DatabaseConnectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("truncate table symbolrelativestrength", connection) { CommandType = System.Data.CommandType.Text })
                {
                    command.ExecuteNonQuery();
                }
            }
        }
    }
}
